﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;

namespace gpao2012
{

    public partial class export : UserControl
    {
        public export()
        {
            InitializeComponent();
        }

        

        private void exportation_Click(object sender, EventArgs e)
        {
          

// Displays a SaveFileDialog so the user can save the Image
// assigned to Button2.
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Fiche de configuration|*.conf";
saveFileDialog1.Title = "Exporté la configuration";
saveFileDialog1.FileName = "Config";
saveFileDialog1.ShowDialog();
   


            SqlConnection con;
            SqlCommand cmd;
            con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=gpaogscofficiel;Integrated Security=True");

            string sqlquery = "SELECT * FROM [gpaogscofficiel].[dbo].[info_soc]";
            con.Open();
            cmd = new SqlCommand(sqlquery, con);

            String[] s = new String[20];
            SqlDataReader mySqDataReader = cmd.ExecuteReader();
            mySqDataReader.Read();
            if (mySqDataReader["id_inf_soc"] != System.DBNull.Value)
            {
               
                
                s[0] = (ascii((string)mySqDataReader["raison_social"]));
                s[0] = (ascii((string)mySqDataReader["adress"]));
                s[1] = (ascii((string)mySqDataReader["ville"]));
                s[2] = (ascii((string)mySqDataReader["pays"]));
                s[3] = (ascii((string)mySqDataReader["tel"]));
                s[4] = (ascii((string)mySqDataReader["fax"]));
                s[5] = (ascii((string)mySqDataReader["codepostal"]));
                s[6] = (ascii((string)mySqDataReader["mail"]));
                s[7] = (ascii((string)mySqDataReader["url"]));
                /*  this.prixminute.Text = mySqDataReader.GetInt32(10).ToString("G");
                  this.prixicppp.Text = mySqDataReader.GetInt32(11).ToString("G");*/

            }
            File.WriteAllLines(saveFileDialog1.FileName, s);
            //File.Close();
            //monStreamWriter = File.AppendText(fichier); 
            
        }

        static string ascii(string s)
        {
            string c = "";
            for (int i = 0; i < s.Length; i++)
            {
                int ch;
                ch = (int)s[i];
                ch = ch - 30;

                c = Convert.ToChar(ch) + c;

            }
            return c;


        }
    }
}
